/*  p6_7.c: Toggle the red LED using the SysTick interrupt */
/* This program sets up the SysTick to interrupt at 1 Hz.
 The system clock is running at 16 MHz.
 1sec/62.5ns=16,000,000 for RELOAD register.
 In the interrupt handler, the red LED is toggled. */


#include "TM4C123GH6PM.h"

int main (void)
{
    /* enable clock to GPIOF at clock gating control register */
    SYSCTL->RCGCGPIO |= 0x20;
    /* enable the GPIO pins for the LED (PF3, 2, 1) as output */
    GPIOF->DIR = 0x0e;
    /* enable the GPIO pins for digital function */
    GPIOF->DEN = 0x0e;
    
    /* Configure SysTick */
    SysTick->LOAD = 16000000-1;   /* reload with number of clocks per second */
    SysTick->CTRL = 7;      /* enable SysTick interrupt, use system clock */

    __enable_irq();         /* global enable interrupt */
    
    while (1)
    {
    }
}

void SysTick_Handler(void)
{
    GPIOF->DATA ^= 2;    /* toggle the red LED */
}

/* This function is called by the startup assembly code to perform system specific initialization tasks. */
void SystemInit(void)
{
    __disable_irq();    /* disable all IRQs */
    
    /* Grant coprocessor access */
    /* This is required since TM4C123G has a floating point coprocessor */
    SCB->CPACR |= 0x00F00000;
}